2026-09-20 · help-desk, tcm, class-notes
A computer is built from billions of tiny switches (transistors). A switch has two reliable states: off and on, which we write as 0 and 1.
Class notes · TCM Security, Practical Help Desk · Section 3
Quick reference: the short version of this section is the Section 3 cheat sheet. The ground-up version is the Code sheets.
By the end of these notes you should be able to:
A computer is built from billions of tiny switches (transistors). A switch has two reliable states: off and on, which we write as 0 and 1.
Why not ten voltage levels for decimal? Because electrical signals are noisy. Telling "high" from "low" is easy and reliable; telling ten levels apart would produce constant errors. Binary trades more digits for rock-solid reliability.
Physical form
0
1
Voltage in a circuit
Low
High
Magnetic hard drive
One magnetic direction
The other direction
SSD flash cell
Charge level read as 0
Charge level read as 1
Optical disc
Land
Pit edge
Fibre-optic cable
Light off
Light on
In any positional number system, each position is worth the base raised to a power:
Decimal 4,825 = 4×10³ + 8×10² + 2×10¹ + 5×10⁰ = 4000 + 800 + 20 + 5Binary works the same way, with base 2:
Position
7
6
5
4
3
2
1
0
Value
128
64
32
16
8
4
2
1
Convert 1011 0110:
128
64
32
16
8
4
2
1
1
0
1
1
0
1
1
0
Add the columns that have a 1: 128 + 32 + 16 + 4 + 2 = 182.
Convert 200:
Step
Largest power that fits
Remainder
Bit set
200
128
72
128 → 1
72
64
8
64 → 1
8
8
0
8 → 1
Every other position is 0 → 1100 1000.
Convert 13: divide by 2 repeatedly and write down the remainders.
13 ÷ 2 = 6 remainder 1 <- least significant bit 6 ÷ 2 = 3 remainder 0 3 ÷ 2 = 1 remainder 1 1 ÷ 2 = 0 remainder 1 <- most significant bit Read upwards: 1101
Hex is base 16: digits 0–9, then A–F (10–15). One hex digit is exactly 4 bits (a nibble), so hex is a compact way to write binary.
Binary
Hex
Binary
Hex
0000
0
1000
8
0001
1
1001
9
0010
2
1010
A
0011
3
1011
B
0100
4
1100
C
0101
5
1101
D
0110
6
1110
E
0111
7
1111
F
Worked example — binary to hex: 1011 0110 → 1011 = B, 0110 = 6 → 0xB6. Check: 11×16 + 6 = 182, matching section 2.2.
Worked example — hex to decimal: 0x2F = 2×16 + 15 = 47.
You'll see hex in MAC addresses (00:1A:2B:3C:4D:5E), IPv6 addresses, colour codes (#FF8800), memory addresses, file hashes and Windows error codes (0x80070005).
Unit
Size
Bit (b)
One binary digit
Nibble
4 bits
Byte (B)
8 bits — 256 possible values (0–255)
An n-bit number has 2ⁿ possible values: 8 bits → 256, 16 bits → 65,536, 32 bits → about 4.3 billion.
Decimal (SI)
Bytes
Binary (IEC)
Bytes
1 KB (kilobyte)
1,000
1 KiB (kibibyte)
1,024
1 MB
1,000² = 1,000,000
1 MiB
1,024² = 1,048,576
1 GB
1,000³
1 GiB
1,024³
1 TB
1,000⁴
1 TiB
1,024⁴
Worked example — the "missing" space ticket. A user's new "1 TB" drive shows as 931 GB in Windows.
Worked example — download time. A user downloads a 2 GB file on a 100 Mbps connection.
Computers only store numbers, so text needs an agreed mapping — a character encoding.
ASCII (1960s) uses 7 bits for 128 characters:
Range
Contents
0–31
Control characters (tab = 9, line feed = 10, carriage return = 13)
32
Space
48–57
Digits 0–9
65–90
A–Z
97–122
a–z
Upper and lower case differ by exactly 32 (A = 65, a = 97) — a single bit.
ASCII only covers English. The 8th bit gave 128 extra characters, but different regions used them differently ("code pages" such as Windows-1252 and ISO-8859-1). The same byte could mean é on one system and something else on another — the source of garbled text.
Unicode gives every character in every writing system a unique number, called a code point, written U+ plus hex: A = U+0041, é = U+00E9, € = U+20AC, the "grinning face" emoji = U+1F600.
UTF-8 stores code points in 1–4 bytes:
Code point range
Bytes
Pattern
U+0000–U+007F
1
0xxxxxxx (identical to ASCII)
U+0080–U+07FF
2
110xxxxx 10xxxxxx
U+0800–U+FFFF
3
1110xxxx 10xxxxxx 10xxxxxx
U+10000–U+10FFFF
4
11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
Worked example — encoding é (U+00E9) in UTF-8:
Base64 turns binary data into safe printable text (letters, digits, +, /). It's used for email attachments, web data and embedding files. Every 3 bytes become 4 characters.
Worked example — "Man" → Base64:
[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('Man')) \
echo -n Man | base64 \
A logic gate is a small circuit of transistors that takes binary inputs and produces a binary output.
Gate
Symbol in expressions
Output 1 when
AND
A · B
Both inputs are 1
OR
A + B
At least one input is 1
NOT
Ā
The input is 0
XOR
A ⊕ B
The inputs differ
NAND
NOT (A AND B)
Not both are 1
A
B
AND
OR
XOR
NAND
0
0
0
0
0
1
0
1
0
1
1
1
1
0
0
1
1
1
1
1
1
1
0
0
NAND is universal: any circuit, including a whole CPU, can be built from NAND gates alone.
Adding one bit to one bit:
A
B
A + B
Sum bit
Carry bit
0
0
0
0
0
0
1
1
1
0
1
0
1
1
0
1
1
2 (binary 10)
0
1
Part
Job
ALU (arithmetic logic unit)
Does the maths and logic — built from adders and gates
Control unit
Reads each instruction and directs everything else
Registers
Tiny, ultra-fast storage inside the CPU for the values being worked on
Program counter
A register holding the address of the next instruction
Clock
Pulses that keep every step in time; 3.5 GHz = 3.5 billion pulses a second
Cache (L1/L2/L3)
Small, fast memory on the CPU holding recently used data
\+-----------\+ \+-----------\+ \+-----------\+
+-->| FETCH |----->| DECODE |----->| EXECUTE |---+ | | get next | | work out | | ALU does | | | | instruc- | | what it | | the work; | | | | tion from | | means | | store the | | | | memory | | | | result | | | +-----------+ +-----------+ +-----------+ | +----------------- program counter moves on -------------+
Worked example — total = price + tax:
One line of code becomes several machine instructions, each going round the cycle.
Level
Typical size
Relative speed
Volatile?
Registers
Bytes
Fastest
Yes
L1 / L2 / L3 cache
KB to tens of MB
Very fast
Yes
RAM
8–64 GB
Fast
Yes
SSD
256 GB–4 TB
Slower
No
HDD
1–20 TB
Slowest
No
Faster memory is smaller and more expensive per byte. The CPU keeps what it needs soon as close as possible — which is why adding RAM, or moving from HDD to SSD, speeds up a slow PC so dramatically.
Each layer hides the complexity of the one below it:
Application Outlook, a web browser High-level code total = price + tax Assembly mov eax, [price] / add eax, [tax] Machine code 8B 05 ... 03 05 ... CPU ALU, registers, control unit Logic gates AND, OR, XOR, NAND Transistors Billions of tiny switches
Approach
How it works
Examples
Trade-off
Compiled
The whole program is translated to machine code before running
C, C++, Go, Rust
Fast; one build per OS and CPU type
Interpreted
An interpreter reads and runs the code at run time
Python, JavaScript, PowerShell, Bash
Portable; slower
Bytecode + JIT
Compiled to an intermediate bytecode, then to machine code at run time
Java, C\
A balance of both
In the real world: "This program won't run on my new ARM laptop" is a compiled-code problem — the software was built for x64. Windows on ARM can emulate many x64 apps, but drivers and some low-level software need a native ARM build.
Reversible?
Needs a key?
Purpose
Examples
Encoding
Yes, by anyone
No
Represent data in a different format
ASCII, UTF-8, Base64, hex
Encryption
Yes, with the key
Yes
Keep data secret
AES, RSA, TLS
Hashing
No (one-way)
No
Verify integrity; store passwords
SHA-256, bcrypt
Term
Definition
Bit
A binary digit, 0 or 1
Nibble
4 bits — one hex digit
Byte
8 bits
Binary / decimal / hexadecimal
Base 2 / base 10 / base 16 number systems
KiB / MiB / GiB
Binary units (1,024-based)
Mbps
Megabits per second — network speed
ASCII
7-bit character encoding with 128 characters
Code page
An 8-bit character set used for one region's extra characters
Unicode
A standard giving every character a unique code point
Code point
The number assigned to a character, e.g. U+00E9
UTF-8
Variable-length (1–4 byte) encoding of Unicode; ASCII-compatible
Base64
Encoding binary data as printable text, 3 bytes → 4 characters
Logic gate
A circuit that computes a logical function of binary inputs
Half / full adder
Gate circuits that add two bits / two bits plus a carry
ALU
Arithmetic logic unit — the part of the CPU that computes
Register
Tiny, very fast storage inside the CPU
Clock speed
Pulses per second that pace the CPU (GHz)
Cache
Small, fast memory close to the CPU
Compiler
Translates source code to machine code before execution
Interpreter
Executes source code directly at run time
Abstraction
Hiding lower-level complexity behind a simpler interface